package edu.sctu.xiangkun.day201506.day20150628;

import java.io.*;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;

import static java.lang.Thread.sleep;

/**
 * Created by user04 on 2015/6/28.
 */
public class InterfaceData {
    public void run(){
            try{
                System.out.println("请等待5秒！");
                sleep(5000);
            }catch(InterruptedException e){
                e.printStackTrace();
            }
    }

    public void getInterfaceData(String path){
        int count = 0;
        File file = new File("D://Json//Json.txt");
        byte[] buffer =  new byte[1024];
        try{
            URL url = new URL(path);
            try {
                URLConnection urlConnection = url.openConnection();
                urlConnection.connect();
                InputStream inputStream = urlConnection.getInputStream();
                FileOutputStream fileOutputStream = new FileOutputStream(file);
                while((count = inputStream.read(buffer)) != -1){
                    System.out.println(new String(buffer,0,count,"utf-8"));

                    fileOutputStream.write(buffer,0,count);
                }
            }catch(IOException e){
                e.printStackTrace();
            }
        }catch(MalformedURLException e){
            e.printStackTrace();
        }
    }
}
